#include <stdint.h>
#include <iso646.h>
#include <stdio.h>

#define elif else if

typedef enum {
    UNKNOWN,
    OPERATOR,
    NUMBER,
    PATTERN,
    WHITESPACE,
    LETTER,
    LPATTERN,
    RPATTERN,
    TERMINAL
} TokenType;

typedef struct {
    uint8_t type;
    char* value;
} Token;

Token match(char c) {
    Token tk;
    if (c >= '0' and c <= '9') {
        tk.type = NUMBER;
    }
    elif ((c >= 'a' and c <= 'z') or (c >= 'A' and c <= 'Z')) {
        tk.type = LETTER;
    }
    elif (c == ' ' or c == '\n' or c == '\t' or c == '\r') {
        tk.type = WHITESPACE;
    }
    elif (c == '+' or c == '-' or c == '*' or c == '/' or c == '=' or c == '!') {
        tk.type = OPERATOR;
    }
    elif (c == ';') {
        tk.type = TERMINAL;
    }
    tk.value = (char[2]){c, '\0'};
    return tk;
}

Token* lex(char *src) {
    Token tokens[sizeof src];
    int seek = 0;
    while (*src != '\0') {
        tokens[seek] = match(*src);
        // printf("%d", tokens[seek].type);
        src++;
        seek++;
    }

    seek = 0;
    Token result[sizeof src];
    while (seek < sizeof tokens) {
        TokenType root_type = tokens[seek].type;
        while (seek+1 < sizeof tokens and tokens[seek+1].type == root_type)
        {
            seek++;
        }
        seek++;
    }
}

int main() {
    char src[8] = "x=1+1;";
    lex(src);
    return 0;
}